<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: redirect.php 204 2013-09-22 07:59:15Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 204 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:59:15 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

include ('includes/application_top.php');

require_once (DIR_FS_INC.'inc.update_banner_click_count.php');

switch($_GET['action']) {
	case 'banner' :
		$banner = $db->db_query("SELECT banners_url from ".TABLE_BANNERS." WHERE banners_id = '".(int) $_GET['goto']."'");
		if ($banner->_numOfRows) {
			update_banner_click_count($_GET['goto']);
			redirect($banner->fields['banners_url']);
		} else
			redirect(href_link(FILENAME_DEFAULT));
		
		break;

	case 'product' :
		if (isset ($_GET['id'])) {
			$product = $db->db_query("SELECT products_url FROM ".TABLE_PRODUCTS_DESCRIPTION." WHERE products_id='".(int) $_GET['id']."' and language_id='".(int) $_SESSION['languages_id']."'");

			if($product->_numOfRows)
				redirect('http://'.$product['products_url']);
			else
				redirect(href_link(FILENAME_DEFAULT));
			
		} else
			redirect(href_link(FILENAME_DEFAULT));
		
		break;

	case 'brand' :
		if (isset ($_GET['brand'])) {
			$brand = $db->db_query("SELECT brand_url from ".TABLE_BRAND_INFO." WHERE brand_id = '".(int) $_GET['brand']."' and languages_id = '".(int) $_SESSION['languages_id']."'");
			if (!$brand->_numOfRows) {
				// no url exists for the selected language, lets use the default language then
				$brand = $db->db_query("SELECT mi.languages_id, mi.brand_url from ".TABLE_BRAND_INFO." mi, ".TABLE_LANGUAGES." l WHERE mi.brand_id = '".(int) $_GET['brand']."' and mi.languages_id = l.languages_id and l.code = '".DEFAULT_LANGUAGE."'");
				if (!$brand_query->_numOfRows)
					redirect(href_link(FILENAME_DEFAULT));
				else
					$db->db_query("UPDATE ".TABLE_BRAND_INFO." set url_clicked = url_clicked+1, date_last_click = now() WHERE brand_id = '".(int) $_GET['brand']."' and languages_id = '".$brand['languages_id']."'");
				
			} else {
				// url exists in selected language
				$db->db_query("UPDATE ".TABLE_BRAND_INFO." set url_clicked = url_clicked+1, date_last_click = now() WHERE brand_id = '".(int) $_GET['brand']."' and languages_id = '".$_SESSION['languages_id']."'");
			}

			redirect($brand->fields['brand_url']);
		} else
			redirect(href_link(FILENAME_DEFAULT));

		break;

	default :
		redirect(href_link(FILENAME_DEFAULT));
		break;
}
?>